package com.zcup.fileupload.controller;

import com.zcup.fileupload.entity.User;
import com.zcup.fileupload.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public String login(User user, HttpSession httpSession){
        User user1 = userService.login(user);
        if (user1 == null) {
            return "redirect:/login.html";
        }else {
            httpSession.setAttribute("user",user1);
            return "redirect:/file/showAll";
        }
    }
}
